package com.sky.mapper;


import com.sky.anno.AutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @AutoFill(OperationType.INSERT)
    @Insert("insert into category (type, name, sort, status, create_time, update_time, create_user, update_user) " +
            "values(#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Category category);

    @AutoFill(OperationType.UPDATE)
    void editCategory(CategoryDTO categoryDTO);

    List<Category> selectByPage(CategoryPageQueryDTO cpqd);

    @Update("update category set status = #{status} where id = #{id}")
    void updateStatus(Integer status, Long id);

    @Delete("delete from category where id = #{id}")
    void deleteCategory(Long id);

    @Select("select * from category where type = #{type}")
    List<Category> selectByType(Integer type);

    @Select("select count(id) from dish where category_id = #{id}")
    List<Integer> selectDishByCategoryId(Long id);

    @Select("select count(id) from setmeal where category_id = #{id}")
    List<Integer> selectSetmealByCategoryId(Long id);
}
